package psd.model.Prolog.Converters;

import org.eclipse.jdt.core.dom.StringLiteral;

import psd.model.IConverter;
import psd.model.Prolog.FactGenerationToolbox;
import psd.model.Prolog.PrologConverter;


public class PrologStringLiteralConverter extends PrologConverter implements
		IConverter<StringLiteral> {

	public PrologStringLiteralConverter(FactGenerationToolbox toolbox) {
		super(toolbox);
	}

	@Override
	public boolean convert(StringLiteral node) {
		String type = typeResolver.getTypeTerm(node);
		String contents = getTextForNode(node).substring(1,
				node.getLength() - 1);
		String value = contents.replaceAll("\\\\", "\\\\\\\\");
		value = value.replaceAll("'", "\\\\'");
		String args[] = { type, quote(value),this.getFilePath(node), this.getLineNumber(node) };
		createBodyFact(node, "literalT", args);
		return true;
	}

}
